package com.recruit.g1.jobmetting.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.recruit.g1.common.response.JsonResult;
import com.recruit.g1.jobmetting.mapper.JobMeetingMapper;
import com.recruit.g1.pojo.jobmetting.dto.JobMeetingAddParam;
import com.recruit.g1.pojo.jobmetting.dto.JobMeetingListQuery;
import com.recruit.g1.pojo.jobmetting.entity.JobMeeting;
import com.recruit.g1.pojo.jobmetting.vo.JobMettingListVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;
import javax.servlet.http.HttpSession;
import java.util.Date;
import java.util.List;

@Validated
@Slf4j
@Api(tags = "招聘会模块")
@RestController
@RequestMapping("/jobMeeting")
public class JobMeetingController {

    @Autowired
    private JobMeetingMapper jobMeetingMapper;

    /**
     * 1.添加招聘会信息
     */
    @PostMapping("add")
    @ApiOperation("添加招聘会信息")
    @ApiOperationSupport(order = 10)
    public JsonResult addJobMeeting(@RequestBody JobMeetingAddParam jobMeetingAddParam, @ApiIgnore HttpSession session) {
        log.debug("jobMeetingAddParam ="+jobMeetingAddParam);

        //获取用户信息(登陆状态拦截)
        //UserSaveParam userSaveParam = (UserSaveParam) session.getAttribute(session.getId());
        /*User userSaveParam =(User) session.getAttribute("currentLoginUser");
        if (userSaveParam == null){
            return JsonResult.fail(StateCode.NOT_LOGIN);
        }*/
        log.debug("session.getId的结果->"+session.getAttribute(session.getId()));


        JobMeeting jobMeeting = new JobMeeting();
        BeanUtils.copyProperties(jobMeetingAddParam, jobMeeting);
        jobMeeting.setStartTime(new Date());

        log.debug("jobMeetingAddParam ="+jobMeetingAddParam);
        jobMeetingMapper.add(jobMeeting);


        return JsonResult.ok();
    }

    /**
     * 2.查询招聘会信息
     */
    @GetMapping("list")
    @ApiOperation("招聘会列表")
    @ApiOperationSupport(order = 20)
    public JsonResult JobMeetingList(JobMeetingListQuery jobMeetingListQuery , @ApiIgnore HttpSession session) {
        log.debug("jobMeetingListQuery ="+jobMeetingListQuery);
        //校验登陆状态
        //UserSaveParam userSaveParam = (UserSaveParam) session.getAttribute(session.getId());
        /*User userSaveParam =(User) session.getAttribute("currentLoginUser");
        if (userSaveParam == null){
            return JsonResult.fail(StateCode.NOT_LOGIN);
        }*/
        String meetingName = jobMeetingListQuery.getMeetingName();
        String location = jobMeetingListQuery.getLocation();

        List<JobMettingListVO> jobMettingListVOS = jobMeetingMapper.jobMeetingList(meetingName,location);
        return JsonResult.ok(jobMettingListVOS);
    }
}
